import { _detail } from '../../common/api/projects'
const computedBehavior = require('miniprogram-computed')
const WxParse = require('../../libs/wxParse/wxParse.js')
const app = getApp()
Component({
  behaviors: [computedBehavior],
  data: {
    id: '',
    detail: null
  },
  computed: {
    sliders () {
      return this.data.detail ? this.data.detail.Images : []
    }
  },
  methods: {
    getDetail() {
      app.loading('加载中')
      _detail(this.data.id).then(res => {
        wx.hideLoading()
        console.log(res)
        if (res.data.IsSuccess) {
          let detail = res.data.Data
          detail.Instruction = detail.Instruction.replace(/、/g, '|')
          detail.Images = detail.Images
          detail.Tag = detail.Tag.split('、')
          detail.coordinates = {
            latitude: detail.PointY,
            longitude: detail.PointX
          }
          let content = detail.Content
          WxParse.wxParse('content', 'html', content, this, 0)
          this.setData({
            detail
          })
        }
      }).catch(err => {
        wx.hideLoading()
        console.log(err)
      })
    },
    recommand () {
      console.log(this.data.id)
    },
    onLoad(options) {
      console.log(app.store.statusBarHeight)
      this.data.id = options.id
      this.getDetail()
    },
    onReady() { },
    onShow() { },
    onShareAppMessage() {
      return app.shareInfo
    }
  }
})